require "http"

class BaiduMap
  def self.geocoder(address)
    url = "http://api.map.baidu.com/geocoder/v2/?address=#{address}&ak=#{Figaro.env.baidu_map_ak}&output=json"
    response = JSON.parse(HTTP.get(url))
    if response["status"] == 0
      response["result"]["location"]
    else
      { "lng" => 0.0, "lat" => 0.0 }
    end
  end

  def self.routematrix(origins, destinations, how = "walking")
    url = "http://api.map.baidu.com/routematrix/v2/#{how}?origins=#{origins}&destinations=#{destinations}&ak=#{Figaro.env.baidu_map_ak}&output=json"
    response = JSON.parse(HTTP.get(url))
    return response
  end
  
end